{include file="public/header" /}
</head>
<body>
    <div id="main-container">
        {include file="public/menu" /}
        <div class="main">
            <div class="notice">{$position.url}</div>
            <div class="main_content">
                <div class="title">
                    <span>{$position.name}</span>
                </div>
				<form  class="layui-form layui-form-pane" id="formrec" method="post" role="form">
					<div class="layui-form-item">
			            <label class="layui-form-label">关键词名称</label>
			            <div class="layui-input-inline">
			                <input class="layui-input" type="text" name="name" placeholder="关键词名称" lay-verify="required">
			            </div>
			        </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">链接地址</label>
                        <div class="layui-input-inline">
                            <input class="layui-input" type="text" name="url" placeholder="链接地址" lay-verify="required">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">替换个数</label>
                        <div class="layui-input-block">
                            <input name="num" lay-verify="number" autocomplete="off" value="0" placeholder="输入数量" class="layui-input w300" type="text">
                        </div>
                    </div>

			        <div class="layui-form-item">
			            <label class="layui-form-label">打开方式</label>
			            <div class="layui-input-inline">
                            <input type="radio" name="otype" value="_blank" title="新开窗口" checked>
                            <input type="radio" name="otype" value="" title="当前窗口">
			            </div>
			        </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否启用</label>
                        <div class="layui-input-block">
                            <input type="checkbox" checked="" name="status" lay-skin="switch" lay-filter="switchTest">
                        </div>
                    </div>

					<div class="layui-form-item">
	                    <label class="layui-form-label"></label>
	                    <div class="layui-input-inline">
			              <button class="btn" lay-submit="" lay-filter="save" data-href='{:url('addsitelink')}'>提交</button>
	                    </div>
			        </div>
				</form>

			</div>
		</div>
	</div>
<script>
layui.use(['form','common'], function(){
        var $ = layui.jquery;
        $form = $('form');
        var form = layui.form(), common=layui.common;

        //监听提交
        form.on('submit(save)', function(data){
            var sub = true;
            var url = $(this).data('href');
            if(url){
                if(sub){
                    $.ajax({
                        url: url,
                        type: 'post',
                        dataType: 'json',
                        data: data.field,
                        success: function (info) {
                            if (info.code == 1) {
                                common.layerAlertSHref(info.msg, '提示', "{:url('sitelink/index')}");
                            }
                            else {
                                common.layerAlertE(info.msg, '提示');
                                $(data.elem).removeAttr("disabled").text("提交");
                            }
                        },
                        beforeSend: function () {
                            $(data.elem).attr("disabled", "true").text("提交中...");
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            common.layerAlertE(textStatus, '提示');
                        }
                    });
                }
            }else{
                common.layerAlertE('链接错误！', '提示');
            }
            return false;
        });
    });
</script>
</body>
</html>